<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE html>
<html>
<head>

    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/Pager.css"/>
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx}/js/jquery.pager.js"></script>
    <script type="text/javascript" src="${ctx}/js/mask.js"></script>
    <script src="${ctx}/js/share.js" type = "text/javascript"></script>
    <link rel="stylesheet" href="${ctx}/css/jquery-ui-1.9.2.custom.css" type="text/css">
    <script src="${ctx}/js/jquery-ui-1.9.2.custom.js" type = "text/javascript" language="javascript"></script>
    <script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>
    <script type="text/javascript" src="${ctx}/js/LodopFuncs.js"></script>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
    </object>


    <title>配包</title>
    <style type="text/css">
        #left {
            float: left;
            width: 100%;
        }

        #saper-container {
            float: left;
            width: 100%;
            background: url(../images/dian.png) repeat-y 59% 0;
        }

        #table_left {
            float: left;
            width: 58%;
            min-height: 300px
        }

        #right {
            float: right;
            width: 40%;
            min-height: 300px
        }

        .xuanzhong {
            color: red;
        }
    </style>
</head>

<body>

<div id="left">
    <div id="saper-container">
        <!-- 遮罩层 -->
        <div id="mask" class="mask"></div>
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">

                <h2>配包</h2>
            </div>
            <div class="subfiled-content">



                <!--表格开始-->
                <div id="table_left" class="table">
                    <div class="search-box clearfix">
                        <div class="kv-item clearfix">
                            <label>清洗批次：</label>
                            <div class="kv-item-content">
                                <input type="text" placeholder="清洗批次" name="qxpc" value="${searchTxt}" class="search_text"
                                       onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                            </div>
                        </div>



                        <div class="kv-item-content" style="margin-left: 20px; ">
                            <input style="padding-left: 32px ;padding-right: 8px"  name="time" id="time" type="text" class="ui-datepicker-time"   />
                            <div class="ui-datepicker-css">
                                <div class="ui-datepicker-quick">
                                    <p>快捷日期<a class="ui-close-date">X</a></p>
                                    <div>
                                        <input @click="timeChangeFun"  class="ui-date-quick-button" type="button" value="今天" alt="0"  name=""/>
                                        <input @click="timeChangeFun" class="ui-date-quick-button" type="button" value="昨天" alt="-1" name=""/>
                                        <input @click="timeChangeFun" class="ui-date-quick-button" type="button" value="7天内" alt="-6" name=""/>
                                        <input @click="timeChangeFun" class="ui-date-quick-button" type="button" value="14天内" alt="-13" name=""/>
                                        <input @click="timeChangeFun" class="ui-date-quick-button" type="button" value="30天内" alt="-29" name=""/>
                                        <input @click="timeChangeFun" class="ui-date-quick-button" type="button" value="60天内" alt="-59" name=""/>
                                    </div>
                                </div>
                                <div class="ui-datepicker-choose">
                                    <p>自选日期</p>
                                    <div class="ui-datepicker-date">
                                        <input @click="timeChangeFun" name="startDate" id="startDate" class="startDate" readonly value="2014/12/20" type="text">
                                        -
                                        <input @click="timeChangeFun" name="endDate" id="endDate" class="endDate" readonly  value="2014/12/20" type="text" disabled  onchange="datePickers()">

                                    </div>
                                </div>
                            </div>
                        </div>

                        <a href="javascript:;" class="sapar-btn sapar-btn-recom query-btn">查询</a>
                    </div>


                    <!--表格具体内容-->
                    <div class="table-box">
                        <table>
                            <thead>
                            <tr>
                                <th>清洗机器</th>
                                <th>清洗软件</th>
                                <th>清洗人</th>
                                <th>开始时间</th>
                                <th>结束时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${qingxiList != null}">
                                <!-- var 是给给他起名字 -->
                                <c:forEach items="${qingxiList}" var="qingxiList">
                                    <tr data="${qingxiList.qingxiLiushui}" class="qingxidata">
                                        <td>${equipMap[qingxiList.qingxiShebeiTiaoma+0].equipName}</td>
                                        <td>${softMap[qingxiList.qingxiRuanjianTiaoma+0].softName}</td>
                                        <td>${emMap[qingxiList.qingxiQingxirenTiaoma]}</td>
                                        <td><fmt:formatDate value="${qingxiList.qingxiKaishiTime}"
                                                            type="date" pattern="MM-dd HH:mm"/></td>
                                        <td><fmt:formatDate value="${qingxiList.qingxiJieshuTime}"
                                                            type="date" pattern="MM-dd HH:mm"/></td>
                                    </tr>
                                </c:forEach>
                            </c:if>

                            </tbody>
                        </table>
                    </div>
                    <div id="kkpager"></div>
                </div><!--表格结束-->

                <div id="right">
                    <!--表格开始-->
                    <div style="height: 40px" class="table">
                        <!--表格操作-->
                        <div style="height: 40px;float: right" class="table-operate ue-clear">
                                <a href="javascript:prn1_printA();">选择打印机</a>
                                <a href="javascript:dayinAll();" class="">全部打印</a>

                        </div>

                        <div class="table-box">
                            <table>
                                <thead>
                                <tr>
                                    <th>网篮条码</th>
                                    <th>包条码</th>
                                    <th>包名称</th>
                                    <th>全选 &nbsp;&nbsp; <input type='checkbox' name='quanxuan' id='quanxuan'/></th>
                                </tr>
                                </thead>
                                <tbody class="packagedetail">

                                </tbody>

                            </table>
                        </div>
                        <div>
                            <input id="leftPage" class="butLeft" type="button" value="上一页"/>
                            <input id="rightPage" class="butRight" type="button" value="下一页"/>
                            <span>到第&nbsp;</span><input id="goPage" class="textBox" type="text" value="1"/><span
                                style="margin-left: 4px;">页&nbsp;</span>
                            <input id="sureBut" class="sure" type="button" value="确定"/>
                            <span>共</span><span class="totalPages" id="totalNum">0</span><span>&nbsp;页</span>
                        </div>
                        <div>

                        </div>


                    </div>
                </div>
            </div>
        </div>
        <div id="saper-ft"></div>
    </div>


</div>
<script type="text/javascript">
    var pageSize = 10, currentPage = 1, totalPage;
    var data = [];
    var LODOP; //声明为全局变量
    function myPrint() {
        CreatePrintPage();
        LODOP.PRINT();
    };
    function myPrintA() {
        CreatePrintPage();
        LODOP.PRINTA();
    };

    function myPreview() {
        CreatePrintPage();
        LODOP.PREVIEW();
    };
    function mySetup() {
        CreatePrintPage();
        LODOP.PRINT_SETUP();
    };
    function myDesign() {
        CreatePrintPage();
        LODOP.PRINT_DESIGN();
    };
    function myBlankDesign() {
        LODOP = getLodop();
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_空白练习");
        LODOP.PRINT_DESIGN();
    };

    function dayinAll() {
        var json = getSelRecord();
        console.log(json);
        $.ajax({
            type: "POST",
            url: "${ctx}/peibao/piliangTiaoma",
            data: {"dataList":JSON.stringify(json)},// 你的formid
            error: function (request) {
                layer.alert("网络错误!");
            },
            success: function (data) {
                if(data.status=="true"){
                    var packageList = data.packageList;
                    for(var i=0;i<packageList.length;i++){
                        var package  = packageList[i];
                        CreatePrintPage(package);
                    }
                }else if(data.status =="shanchu"){
                    var packageList = data.packageList;
                    for(var i=0;i<packageList.length;i++){
                        var package  = packageList[i];
                        CreatePrintPage(package);
                    }
                    layer.alert(data.msg);
                }else if(data.status=="false"){
                    alert("打印失败");
                }
            }
        });

//        for (var i = 0; i < json.length; i++) {
//            console.log(json.length)
//            var huishouWupinbaoTiaoma = json[i].packageTiaoma;
//            var baoName = json[i].packageName;
//            var huishouWupinbaoMuban = json[i].packId;
//            dayin(huishouWupinbaoTiaoma, baoName, huishouWupinbaoMuban);
//        }

    }
    function dayin(huishouWupinbaoTiaoma, baoName, huishouWupinbaoMuban) {
        $.get('${ctx}/peibao/tiaoma.do?huishouWupinbaoTiaoma=' + huishouWupinbaoTiaoma + "&huishouWupinbaoMuban=" + huishouWupinbaoMuban, function (data) {
            console.log(data);
            if(data.print=="1"){
                CreatePrintPage(data.packImfor);
            }else{
                alert("当前包不支持打印条码请到配置管理里面修改");
            }

        })
    }

    function prn1_printA() {
        CreateOneFormPage();
        LODOP.PRINTA();
    };

    function CreateOneFormPage() {
        var miejuntime = "2017-1-1";
        var baoName = "测试";
        var depName = "测试";
        var guoqitime = "2017-1-1";
        var days = "8";
        var baoTiaoma = "111111";
        var peibaoren = "沈草";
        var shenheRen ="";
        var guanbaoRen = "";
        console.log(baoName);
        LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_名片");
        LODOP.ADD_PRINT_RECT(10, 10, 256, 142, 0, 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.SET_PRINT_STYLE("FontName", "微软雅黑");
        LODOP.ADD_PRINT_TEXT(10, 10, 220, 38, baoName);
        LODOP.ADD_PRINT_TEXT(16, 160, 140, 38, depName);
        LODOP.ADD_PRINT_RECT(38, 10, 256, 116, 0, 1);
        LODOP.ADD_PRINT_RECT(85, 10, 256, 116, 0, 1);
        LODOP.ADD_PRINT_TEXT(43, 10, 150, 38, "灭菌日期：" + miejuntime);
        LODOP.ADD_PRINT_TEXT(55,10,150,38,"有效期"+days+"天");
        LODOP.ADD_PRINT_TEXT(70, 10, 150, 38, "失效日期：" + guoqitime);
        LODOP.ADD_PRINT_TEXT(43, 160, 150, 19, "配包人：" + peibaoren);
        LODOP.ADD_PRINT_TEXT(55, 160, 150, 19, "审核人："+shenheRen);
        LODOP.ADD_PRINT_TEXT(70, 160, 150, 19, "打包人："+guanbaoRen);
        LODOP.SET_PRINT_STYLEA(2, "FontName", "隶书");
        LODOP.SET_PRINT_STYLEA(2, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(3, "FontSize", 11);
        LODOP.ADD_PRINT_TEXT(98, 10, 150, 19, "条码");
        LODOP.ADD_PRINT_BARCODE(90, 50, 200, 25, "Code39", baoTiaoma);
        //LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
        LODOP.ADD_PRINT_TEXT(125, 10, 150, 19, "条码");
        LODOP.ADD_PRINT_BARCODE(120, 50, 200, 30, "Code39", baoTiaoma);

    }
    //判断是否为空


    function CreatePrintPage(packImfor) {
        var miejuntime = packImfor[6];
        var baoName = packImfor[3];
        var depName = packImfor[2];
        var guoqitime = packImfor[7];
        var days = packImfor[8];
        var baoTiaoma = packImfor[4];
        var queshi = packImfor[0];
        var peibaoren = packImfor[1];
        var shenheRen = packImfor[9];
        var guanbaoRen = packImfor[10];
        LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
        if(packImfor[11]!=""){
            var name = packImfor[11];
            console.log(name);
//            var arr = name.split("/");
            LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_名片");
            LODOP.SET_PRINT_PAGESIZE(1,70,40,"");
            LODOP.ADD_PRINT_RECT(10, 10, 256, 142, 0, 1);
            LODOP.SET_PRINT_STYLE("FontSize", 8);
            LODOP.SET_PRINT_STYLE("FontName", "微软雅黑");
            LODOP.ADD_PRINT_TEXT(10, 10, 240, 38, baoName);
            LODOP.ADD_PRINT_TEXT(16, 160, 140, 38, depName);
            LODOP.ADD_PRINT_RECT(38, 10, 256, 116, 0, 1);
            LODOP.ADD_PRINT_RECT(85, 10, 256, 116, 0, 1);
            LODOP.ADD_PRINT_TEXT(43,10,160,20,name);
            LODOP.ADD_PRINT_TEXT(56, 10, 160, 38, "灭菌日期：" + miejuntime);
            LODOP.ADD_PRINT_TEXT(72, 10, 160, 38, "失效日期：" + guoqitime + "(" + days + ")天");
            LODOP.ADD_PRINT_TEXT(43, 180, 150, 19, "配包人：" + peibaoren);
            LODOP.ADD_PRINT_TEXT(55, 180, 150, 19, "审核人："+shenheRen);
            LODOP.ADD_PRINT_TEXT(72, 180, 150, 19, "打包人："+guanbaoRen);
            LODOP.SET_PRINT_STYLEA(2, "FontName", "隶书");
            LODOP.SET_PRINT_STYLEA(2, "FontSize", 14);
            LODOP.SET_PRINT_STYLEA(3, "FontSize", 11);
            LODOP.ADD_PRINT_TEXT(98, 10, 150, 19, "条码");
            LODOP.ADD_PRINT_BARCODE(90, 50, 200, 25, "Code39", baoTiaoma);
            //LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
            LODOP.ADD_PRINT_TEXT(125, 10, 150, 19, "条码");
            LODOP.ADD_PRINT_BARCODE(120, 50, 200, 30, "Code39", baoTiaoma);
        }else{
            LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_名片");
            LODOP.SET_PRINT_PAGESIZE(1,70,40,"");
            LODOP.ADD_PRINT_RECT(10, 10, 256, 142, 0, 1);
            LODOP.SET_PRINT_STYLE("FontSize", 8);
            LODOP.SET_PRINT_STYLE("FontName", "微软雅黑");
            LODOP.ADD_PRINT_TEXT(10, 10, 240, 38, baoName);
            LODOP.ADD_PRINT_TEXT(16, 160, 140, 38, depName);
            LODOP.ADD_PRINT_RECT(38, 10, 256, 116, 0, 1);
            LODOP.ADD_PRINT_RECT(85, 10, 256, 116, 0, 1);
            LODOP.ADD_PRINT_TEXT(43, 10, 160, 38, "灭菌日期：" + miejuntime);
            LODOP.ADD_PRINT_TEXT(70, 10, 160, 38, "失效日期：" + guoqitime + "(" + days + ")天");
            LODOP.ADD_PRINT_TEXT(43, 180, 150, 19, "配包人：" + peibaoren);
            LODOP.ADD_PRINT_TEXT(55, 180, 150, 19, "审核人："+shenheRen);
            LODOP.ADD_PRINT_TEXT(70, 180, 150, 19, "打包人："+guanbaoRen);
            LODOP.SET_PRINT_STYLEA(2, "FontName", "隶书");
            LODOP.SET_PRINT_STYLEA(2, "FontSize", 14);
            LODOP.SET_PRINT_STYLEA(3, "FontSize", 11);
            LODOP.ADD_PRINT_TEXT(98, 10, 150, 19, "条码");
            LODOP.ADD_PRINT_BARCODE(90, 50, 200, 25, "Code39", baoTiaoma);
            //LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
            LODOP.ADD_PRINT_TEXT(125, 10, 150, 19, "条码");
            LODOP.ADD_PRINT_BARCODE(120, 50, 200, 30, "Code39", baoTiaoma);
        }

        //LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
//        LODOP.PREVIEW();
        LODOP.PRINT();
    };
    function myAddHtml() {
        LODOP = getLodop();
        LODOP.PRINT_INIT("");
        LODOP.ADD_PRINT_HTM(0, 0, "100%", "100%", document.getElementById("textarea01").value);
    };


    //判断是否为空
    function isNullOrEmpty(strVal) {
        strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }

    $(function () {

        var totalPage = ${total};
        var pageNo = getParameter('pageIndex');
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //链接前部
            hrefFormer: '${ctx}/peibao/peibaoList',
            //链接尾部
            hrefLatter: '.do',
            getLink: function (n) {
                return this.hrefFormer + this.hrefLatter + "?pageIndex=" + n + "&searchTxt=" + $(".search_text").val() + "&st=" + $("#st").val() + "&et=" + $("#et").val();
            }
        });

        $(".query-btn").click(function () {
            var startTime = $("#st").val();
            var start = new Date(startTime.replace("-", "/").replace("-", "/"));
            var endTime = $("#et").val();
            var end = new Date(endTime.replace("-", "/").replace("-", "/"));
            if (end < start) {
                alert("终止时间不能在起始时间之前");
            }
            window.location.href = "${ctx}/peibao/qingxiList.do?searchTxt=" + $(".search_text").val() + "&st=" + startTime + "&et=" + endTime;
        });


        $(".qingxidata").click(function () {
            $(this).addClass("xuanzhong").siblings().removeClass("xuanzhong");
            var liushuiId = $(this).attr("data");
            console.log("comeon");
            $.ajax({
                type: "post",
                url: "${ctx}/peibao/peibaoMingxiList.do?id=" + liushuiId,
                error: function () {
                    layer.alert("网络故障，稍后再试");
                },
                success: function (data) {
                    if (data.status == "true") {
                        appendTable(data);
// 		 	           	 var dataList = data.zsWanglanpacklist;
// 		 	           	 console.log(dataList);
// 		 	           	 $(".packagedetail").empty();
// 		 	           	 var str = "";
// 		 	           	 if(dataList.length!=0){
// 		 	           		for(var i = 0; i<dataList.length;i++){
// 		 	           			var packageZhuangtai = dataList[i].packageZhuangtai;

// 		 	           			if(packageZhuangtai=='1'){
// 		 	           			str += "<tr class='packMx "+dataList[i].packageTiaoma+"'  data='"+dataList[i].packageId+"'><td>"+dataList[i].wanglanTiaoma+"</td>"
// 			 	           		+"<td>"+dataList[i].packageTiaoma+"</td><td>"+dataList[i].packageName+"</td>"
// 		 	           			+"<td><input type='checkbox' name='key''/>&nbsp;&nbsp;<a href='javascript:;' onclick='dayin(\""+dataList[i].packageTiaoma+"\",\""+dataList[i].packageName+"\",\""+dataList[i].packageId+"\")'>打印</a></td></tr>";
// 		 	           			}else{
// 		 	           			str += "<tr class='packMx "+dataList[i].packageTiaoma+"'  data='"+dataList[i].packageId+"'><td>"+dataList[i].wanglanTiaoma+"</td>"
// 			 	           		+"<td>"+dataList[i].packageTiaoma+"</td><td>"+dataList[i].packageName+"</td>"
// 		 	           			+"<td>已配包&nbsp;&nbsp;<a href='javascript:;' onclick='dayin(\""+dataList[i].packageTiaoma+"\",\""+dataList[i].packageName+"\",\""+dataList[i].packageId+"\")'>打印</a></td></tr>";
// 		 	           			}

// 			 	           	 }
// 		 	           	 }
// 		 	           	 $(".packagedetail").append(str);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        });

        $(document).keydown(function (event) {
            var oPlay0 = document.getElementById("audio");
            var oPlay1 = document.getElementById("audio1");
            var peibaoren = $("input[name='peibaoren']").val();
            if (event.keyCode == 13) {
                if ($("#peibaoren").is(":focus") && !isNullOrEmpty(peibaoren)) {
                    $("#peibao").click();
                }
            }
        });

        //全选
        $("#quanxuan").live("click", function () {
            var that = $(this);
            var flag = true;
            if(that.prop('checked')){
                flag = true;
            }else{
                flag = false;
            }
            $(".packagedetail").find("input[name='key']").each(function () {
                ck = $(this);
                if (flag) {
                    ck.prop('checked', true);
                } else {
                    ck.prop('checked', false);
                }
            });
        })

        $(".packMx").live("dblclick", function () {
            $(this).addClass("xuanzhong").siblings().removeClass("xuanzhong");
            var packId = $(this).attr("data");
            //找儿子的典例
            var name = $(this).find("td:eq(2)").text();
            layer.open({
                type: 2,
                title: name + '包明细',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['800px', '520px'],
                content: '${ctx}/wutiaoma/findQixieListPeibao.do?id=' + packId + '&name=' + name
            });
        })

        $("#sureBut").click(function () {
            goPage();
        });
        $("#leftPage").click(function () {
            leftPages();
        });
        $("#rightPage").click(function () {
            rightPages();
        });

        $(".check").click(function () {
            var ok = true;
            var ck = getSelRecord();
            var peibaoren = $("input[name='peibaoren']").val();
            if (isNullOrEmpty(peibaoren)) {
                ok = false;
                alert("配包人不能为空");
            }
            if (ck.length == 0) {
                ok = false;
                alert("没有选中项目");
            }
            if (ok) {
                showMask();
                $.ajax({
                    type: "post",
                    data: {"dataList": JSON.stringify(ck)},
                    dataType: "json",
                    url: "${ctx}/peibao/peibaobaocun.do",
                    error: function () {
                    },
                    success: function (data) {
                        if (data.status == true) {
                            hideMask();
                            layer.alert("配包成功,点击确定继续配包", function (index) {
                                window.location.reload();
                            });
// 							var packageTiaoma = data.packageTiaoma;
// 							console.log(packageTiaoma);
// 							layer.alert(data.msg);
// 							$("#quanxuan").prop("checked",false);
// 							$("#quanxuan").attr("disabled","disabled");
// 							for(var i = 0;i<packageTiaoma.length;i++){
// 								$("."+packageTiaoma[i]).find("input[name='key']").prop("checked",false);
// 								$("."+packageTiaoma[i]).find("input[name='key']").attr("disabled","disabled");
// 							}
                        } else {
                            hideMask();
                            layer.alert(data.msg);
                        }

                    }
                })
            }
        })

    });


    //  分页
    function appendTable(dataList) {
        currentPage = 1;
        data = dataList.zsWanglanpacklist;
//         packageId = dataList.packageId;
        creatTab();
    }
    //获得总页数
    function totalPages() {
        //如果刚好除尽
        if (data.length % pageSize == 0) {
            totalPage = data.length / pageSize;
        }
        else {
            totalPage = parseInt(data.length / pageSize) + 1;
        }
    }

    //上一页
    function leftPages() {
        if (currentPage != 1) {
            currentPage--;
            //开始创建
            creatTab();
        }
    }
    //下一页
    function rightPages() {
        if (currentPage != totalPage) {
            currentPage++;
            //开始创建
            creatTab();
        }
    }
    //到第几页去
    function goPage() {
        currentPage = document.getElementById('goPage').value;
        //如果输入的页数超出总页数，则到最后一页去！
        if (currentPage > totalPage) {
            currentPage = totalPage;
        }
        if (currentPage < 1) {
            currentPage = 1;
        }
        creatTab();
    }

    function creatTab() {
        $("#quanxuan").prop("checked",false);
        //清空数据
        $(".packagedetail").empty();
//  		$("#checkalltwo").attr("checked",false);
        //总页数
        totalPages();
        $('#totalNum').text(totalPage);
        //插入页数
        $('#goPage').val(currentPage);
        var str = '';
//		$("#packagedetail").empty();
        currentRows = (totalPage == 1 || currentPage == totalPage) ? data.length : currentPage * pageSize;
        console.log(currentPage);
        console.log(currentRows);
        for (var i = (currentPage - 1) * pageSize; i < currentRows; i++) {
            var packageZhuangtai = data[i].packageZhuangtai;
            if (packageZhuangtai == '1') {
                str += "<tr class='packMx " + data[i].packageTiaoma + "'  data='" + data[i].packageId + "'><td>" + data[i].wanglanTiaoma + "</td>"
                    + "<td>" + data[i].packageTiaoma + "</td><td>" + data[i].packageName + "</td>"
                    + "<td><input type='checkbox' name='key''/>&nbsp;&nbsp;<a href='javascript:;' onclick='dayin(\"" + data[i].packageTiaoma + "\",\"" + data[i].packageName + "\",\"" + data[i].packageId + "\")'>打印</a></td></tr>";
            } else {
                str += "<tr  class='packMx " + data[i].packageTiaoma + "'  data='" + data[i].packageId + "'><td>" + data[i].wanglanTiaoma + "</td>"
                    + "<td>" + data[i].packageTiaoma + "</td><td>" + data[i].packageName + "</td>"
                    + "<td>已配包&nbsp;&nbsp;<input type='checkbox' name='key''/></td></tr>";
            }
        }
        console.log(str);
        $(".packagedetail").append(str);
    }

    function getSelRecord() {
        var chk_value = [];
        $('input[name="key"]:checked').each(function () {
            var packId = $(this).parent().parent().attr("data");
            var peibaoren = $("input[name='peibaoren']").val();
            var wanglanTiaoma = $(this).parent().parent().find("td:eq(0)").text();
            var packageTiaoma = $(this).parent().parent().find("td:eq(1)").text();
            var packageName = $(this).parent().parent().find("td:eq(2)").text();
            var json = {
                "packId": packId,
                "wanglanTiaoma": wanglanTiaoma,
                "packageTiaoma": packageTiaoma,
                "packageName": packageName,
                "peibaoren": peibaoren
            };

            chk_value.push(json);
        });
        return chk_value;
    }
</script>
</body>
</html>